package com.jiwei.community.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiwei.community.entity.User;
import com.jiwei.community.dao.UserMapper;
import com.jiwei.community.enums.AppHttpCodeEnum;
import com.jiwei.community.service.UserService;
import com.jiwei.community.utils.BeanCopyUtils;
import com.jiwei.community.vo.ResponseResult;
import com.jiwei.community.vo.UserInfoVo;
import org.springframework.stereotype.Service;

/**
 * (User)表服务实现类
 *
 * @author jiwei
 * @since 2024-03-15 09:42:32
 */
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public User getByUserId(Long userId) {
        User user = this.baseMapper.getUserById(userId);
        if (user != null) {
            return user;
        }
        return null;
    }

    @Override
    public ResponseResult getUserInfoById(Long id) {
        User user = getByUserId(id);
        if (user == null)return ResponseResult.errorResult(AppHttpCodeEnum.BAD_REQUEST,"查询不到该用户");
        UserInfoVo infoVo = BeanCopyUtils.copyBean(user,UserInfoVo.class);
        return ResponseResult.okResult(infoVo);
    }
}

